const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    openid: "sdhh444",
    courseType: "",
    classHour: "",
    totalMoney: "",
    orderStatus: null,
    odStatus: "未完成",
    btn:"确定完成",
    dataId:null,
   studentId:'',
    teacherName:'',
    livel:'',
    platform:'',
    system:'',
    stuName:'',
  },

  // 更改订单状态
  changeOrderStatus(){
    let that = this;
    if (app.globalData.evaluted==0){
      wx.request({
        url: "https://www.enjoyyz.com:8443/yinzuo/done?orderid=" + that.data.dataId,
        method: 'PUT',
        // data: {
        //   orderid:that.data.dataId,
        // },
        success(res) {
          console.log(that.data.dataId, 'that.data.dataId')
        }
      })
    } else if (app.globalData.evaluted == 1){
      wx.request({
        url: 'https://www.enjoyyz.com:8443/yinzuo/evaContent',
        method: 'GET',
        data: {
          orderid: that.data.dataId
        },
        success(res) {
          console.log(res, 'res')
           app.globalData.commentData = res.data.data.content,
            app.globalData.commentDate = new Date(res.data.data.evaTime).toLocaleString()
            // that.setData({
            //   commentData: res.data.data.content,
            //   commentDate: new Date(res.data.data.evaTime).toLocaleString(),
            // })
          // console.log(commentData, 'commentData')
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      dataId :options.dataId,
      orderStatus: app.globalData.currentStatus
    })
    console.log(options.dataId,'options.dataId');
    console.log("当前的状态码为：");
    console.log(this.data.orderStatus)
    // let dataId = options.dataId;
    // let status = options.status;
    // this.getOpenid();
    // this.getClassList(this.data.openid, dataId, status);

    let that = this;
    wx.request({
      url: "https://www.enjoyyz.com:8443/yinzuo/mycourse",
      data: {
        openid: app.globalData.openid,
        status: that.data.orderStatus
      },
      success(res) {
        console.log(res.data,'res.data')
        app.globalData.evaluted = res.data[app.globalData.courseIndex].evaluted;
        if (that.data.orderStatus === 0 && res.data[app.globalData.courseIndex].evaluted == 0) {
          if (res.data[app.globalData.courseIndex].status==2){
            that.setData({
              odStatus: "未接单",
              btn: '确定完成'
            })
          }else{
            that.setData({
              odStatus: "未完成",
              btn: '确定完成'
            })
          }
        } else if (that.data.orderStatus === 1&& res.data[app.globalData.courseIndex].evaluted == 0) {
          that.setData({
            odStatus: "已完成",
            btn:'确定'
          })
        } else if (res.data[app.globalData.courseIndex].evaluted == 1){
          that.setData({
            odStatus: "已评价",
            btn: '确定'
          })
        }
        that.setData({   
          courseType: res.data[app.globalData.courseIndex].courseType,
          classHour: res.data[app.globalData.courseIndex].classHour,
          totalMoney: res.data[app.globalData.courseIndex].totalMoney,
          studentId: res.data[app.globalData.courseIndex].name,
          teacherName: res.data[app.globalData.courseIndex].name,
          livel: res.data[app.globalData.courseIndex].level,
          platform: res.data[app.globalData.courseIndex].platform,
          system: res.data[app.globalData.courseIndex].system,
          stuName: res.data[app.globalData.courseIndex].stuName,
        })
      }
    })
  },


  copy: function (e) {
    var that = this;
    console.log(e);
    wx.setClipboardData({
      data: that.data.stuName,
      success: function (res) {
        wx.showToast({
          title: '复制成功',
        });
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})